//
//  LJFMySetController.m
//  SevenZhou
//
//  Created by qianfeng on 15/9/27.
//  Copyright (c) 2015年 ljf. All rights reserved.
//

#import "LJFMySetController.h"
#import "LJFVLoginOrRegisterController.h"

@interface LJFMySetController ()<UIAlertViewDelegate,LoginSuccessDelegate>

@property (weak, nonatomic) IBOutlet UIView *bgView;

@property (weak, nonatomic) IBOutlet UILabel *name;

@end

@implementation LJFMySetController
{
    BOOL _isLogin;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self setNameLabel];
    
    [self addTapToBgView];
}

- (void)setNameLabel
{
    if (_nameStr.length > 0)
    {
        _name.text = _nameStr;
        _isLogin = YES;
    }
    else
    {
        _isLogin = NO;
    }
}

- (void)addTapToBgView
{
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap)];
    [_bgView addGestureRecognizer:tap];
}

- (void)tap
{
    if (_isLogin)
    {
        UIAlertView *alter = [[UIAlertView alloc] initWithTitle:@"提示" message:@"是否退出当前账号?" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
        [alter show];
    }else
    {
        LJFVLoginOrRegisterController *login = [self.storyboard instantiateViewControllerWithIdentifier:@"LJFVLoginOrRegisterController"];
        login.mydelegate = self;
        [self presentViewController:login animated:YES completion:nil];
    }
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

#pragma mark -UIAlertViewDelegate

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 1)
    {
        [_mydelegate MySetdidRegisterIDWithController:self];
        
        [self back:nil];
    }
}

#pragma mark -LoginSuccessDelegate

- (void)LoginSuccess:(LJFVLoginOrRegisterController *)controll successDictionary:(NSDictionary *)dict
{
    _name.text = dict[@"user"][@"name"];
    _isLogin = YES;
    
    [_mydelegate MySetdidLoginIDWithController:self WithSuccessData:dict];
}


- (IBAction)back:(id)sender
{
    [self dismissViewControllerAnimated:NO completion:nil];
}

@end
